package com.design.patterns.strategy;

import java.util.HashMap;
import java.util.Map;

/**
 * @version V1.0
 * @Description： <p> 策略工厂 </p>
 * @Author xiayong
 * @CreatTime 2020/10/21 16:13
 */
public class PromotionStrategyFactory {
    private static final Map<String, PromotionStrategy> PROMOTION_STRATEGY_MAP = new HashMap<>();
    // 初始化策略
    static {
        PROMOTION_STRATEGY_MAP.put(PromotionKey.FAN_XIAN, new FanXianPromotionStrategy());
        PROMOTION_STRATEGY_MAP.put(PromotionKey.LI_JIAN, new LiJianPromotionStrategy());
        PROMOTION_STRATEGY_MAP.put(PromotionKey.MAN_JIAN, new ManJianPromotionStrategy());
    }

    private static final PromotionStrategy emptyPromotionStrategy = new ManJianPromotionStrategy();

    private PromotionStrategyFactory() {
    }

    public static PromotionStrategy getPromotionStrategy(String promotionKey){
        PromotionStrategy promotionStrategy = PROMOTION_STRATEGY_MAP.get(promotionKey);
        return null == promotionKey ? emptyPromotionStrategy : promotionStrategy;
    }

    private interface PromotionKey {
        String LI_JIAN = "LI_JIAN";
        String MAN_JIAN = "MAN_JIAN";
        String FAN_XIAN = "FAN_XIAN";
    }
}
